package com.generate.library;

import java.awt.Component;
import java.awt.Container;
import java.util.ArrayList;
import java.util.List;

public class ComponentUtils {
	private ComponentUtils() {
	}

	public static List<Component> getAllComponents(final Container c) {
		Component[] comps = c.getComponents();
		List<Component> compList = new ArrayList<Component>();
		for (Component comp : comps) {
			compList.add(comp);
			if (comp instanceof Container)
				compList.addAll(getAllComponents((Container) comp));
		}
		return compList;
	}

	public static <T> List<T> getAllComponents(final Container c,
			Class<T> classType) {
		Component[] comps = c.getComponents();
		List<T> compList = new ArrayList<T>();
		for (Component comp : comps) {
			if (comp.getClass().equals(classType)) {
				compList.add((T) comp);
			}
			if (comp instanceof Container) {
				compList.addAll(getAllComponents((Container) comp, classType));
			}
		}
		return compList;
	}

}
